package com.ncr.travel.appmgr.service.converter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.ncr.travel.appmgr.model.AuditFieldJson;
import com.ncr.travel.appmgr.model.ColumnSpecificationJson;
import com.ncr.travel.appmgr.model.ErrorTextJson;
import com.ncr.travel.appmgr.model.FontOptionsJson;
import com.ncr.travel.appmgr.model.FunctionJson;
import com.ncr.travel.appmgr.model.RowSpecificationJson;
import com.ncr.travel.appmgr.model.RuleControlsJson;
import com.ncr.travel.appmgr.model.RuleJson;
import com.ncr.travel.appmgr.model.StationsAuditCriteriaJson;
import com.ncr.travel.appmgr.model.TableDefinitionJson;
import com.ncr.travel.appmgr.model.TextEntryJson;
import com.ncr.travel.appmgr.model.shared.Alignment;
import com.ncr.travel.appmgr.model.shared.AuditField;
import com.ncr.travel.appmgr.model.shared.Category;
import com.ncr.travel.appmgr.model.shared.ColumnSpecification;
import com.ncr.travel.appmgr.model.shared.ErrorText;
import com.ncr.travel.appmgr.model.shared.FontOptions;
import com.ncr.travel.appmgr.model.shared.Function;
import com.ncr.travel.appmgr.model.shared.RowSpecification;
import com.ncr.travel.appmgr.model.shared.Rule;
import com.ncr.travel.appmgr.model.shared.RuleControls;
import com.ncr.travel.appmgr.model.shared.StationsAuditCriteria;
import com.ncr.travel.appmgr.model.shared.TableDefinition;
import com.ncr.travel.appmgr.model.shared.Text;
import com.ncr.travel.appmgr.model.shared.TextEntry;
import com.ncr.travel.appmgr.service.model.ScreenConfiguration;
import com.ncr.travel.tas.configuration.exceptions.TableColumnException;
import com.ncr.travel.tas.configuration.exceptions.TableRowException;
import com.ncr.travel.tas.configuration.model.ConfigurationNode;
import com.ncr.travel.tas.configuration.model.ConfigurationValue;
import com.ncr.travel.tas.configuration.model.TableColumn;
import com.ncr.travel.tas.configuration.model.TableRow;
import com.ncr.travel.tas.configuration.model.TableValue;
import com.ncr.travel.tas.shared.configuration.ConfigurationKey;
import com.ncr.travel.tas.shared.configuration.ConfigurationNodeEnum;
import com.ncr.travel.tas.shared.configuration.ConfigurationValueEnum;

@Component
public class ScreenConfigurationConverterImpl implements ScreenConfigurationConverter {

	private static final Logger logger = LoggerFactory.getLogger(ScreenConfigurationConverterImpl.class);

	public ScreenConfigurationConverterImpl() {
		super();
	}

	@Override
	public ConfigurationNode toConfigurationNode(ScreenConfiguration screenConfiguration) {
		logger.info("Entered getConfigurationNodeFromScreenConfiguration()");

		long screenConfigurationID = screenConfiguration.getId();
		List<Function> functions = screenConfiguration.getFunctions();

		logger.info("Dumping function contents (screen " + screenConfigurationID + ") before persistence");

		Function redressSettingsFunction = functions.get(0);

		StationsAuditCriteria auditCriteria = redressSettingsFunction.getAuditCriteria();

		// Doubt- to which field this AuditCriteriaType corresponds to
		auditCriteria.getAuditCriteriaType();
		List<AuditField> stations = auditCriteria.getStations();

		ConfigurationNode redressConfiguration = new ConfigurationNode(ConfigurationNodeEnum.APPMGR);
		redressConfiguration.setName(redressSettingsFunction.getName());
		redressConfiguration.setDescription("Settings to configure kiosks regarding Redress activation at kiosks");

		// flag function as on or off
		// Doubt over this entry- from where to get this entry value
		// corresponding to current implementation
		ConfigurationValue enabled = new ConfigurationValue("enabled", true);

		// add audit criteria flag per example in UI spec
		ConfigurationValue setAllStations = new ConfigurationValue("setAllStations", auditCriteria.isAllStations());

		// add sub container for station data
		ConfigurationValue stationsInConfig = new ConfigurationValue("Stations", "Stations Listing");

		for (AuditField auditField : stations) {

			// stationsInConfig.addChildValue(new
			// ConfigurationValue("ATL",false));
			stationsInConfig.addChildValue(new ConfigurationValue(auditField.getStation(), auditField.isAvailable()));

		}

		// add to set for redress configuration settings
		Set<ConfigurationValue> settings = new HashSet<ConfigurationValue>();
		settings.add(enabled);
		settings.add(setAllStations);
		settings.add(stationsInConfig);

		// add to node
		redressConfiguration.setConfigurations(settings);

		return redressConfiguration;
	}

	@Override
	public ScreenConfiguration toScreenConfiguration(final ConfigurationValue value) {

		ScreenConfiguration screenConfiguration = new ScreenConfiguration();
		if (value.getTag() != null) {
			try {
				screenConfiguration.setName(value.getTag().toString());
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		screenConfiguration.setId((int)value.getId());
		screenConfiguration.setKey(value.getKeyName());
		screenConfiguration.setUrl(value.getValue().toString());

		// parse the functions out of the screen configuration value
		List<Function> functions = getFunctions(value);
		screenConfiguration.setFunctions(functions);

		// parse the text out of the screen configuration value
		List<Text> text = getText(value);
		screenConfiguration.setText(text);

		// parse the rules out of the screen configuration value
		List<Rule> rules = getRules(value);
		screenConfiguration.setRules(rules);

		logger.debug("value.keyName = '" + value.getKeyName() + "'");
		logger.debug("value.value = '" + value.getValue() + "'");

		return screenConfiguration;
	}

	private List<Text> getText(final ConfigurationValue screenCV) {
		// check to see if the 'text' bucket has any children.
		// if so, they are a list of text definitions.
		final ConfigurationValue textListCV = screenCV.findChild(ConfigurationKey.TEXT);
		final List<Text> textList = new ArrayList<Text>();
		if (textListCV != null) {
			for (final ConfigurationValue textCV : textListCV.getChildValues()) {
				Text text;
				if (TextEntryJson.class.getName().equals(textCV.getObjectType())) {
					// text entry i.e. Instruction Text / Button Text
					final TextEntry textEntry = new TextEntryJson();
					textEntry.setValue((String) textCV.getValue());
					text = textEntry;
				} else if (ErrorText.class.getName().equals(textCV.getObjectType())) {
					// Error Text
					final ErrorTextJson errorCode = new ErrorTextJson();
					errorCode.setCode(Integer.valueOf(textCV.getKeyName()));
					errorCode.setMessage((String) textCV.getValue());
					text = errorCode;
				} else {
					logger.error("Invalid ObjectType for Text Configurations");
					continue;
				}
				text.setId((int)textCV.getId());
				text.setName(textCV.getKeyName());
				// check for font options
				final ConfigurationValue fontOptionsCV = textCV.findChild("FontOptions");
				if (fontOptionsCV != null) {
					try {
						final FontOptionsJson fontOptions = this.createFontOptionsFromConfigurationValue(fontOptionsCV);
						text.setFontOptions(fontOptions);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						// how or where to log this in this layer?
						e.printStackTrace();
					}
				}
				// Category
				final ConfigurationValue categoryCV = textCV.findChild("Category");
				if (categoryCV != null) {
					text.setCategory(Category.valueOf((String) categoryCV.getValue()));
				}
				// multiLine
				final ConfigurationValue multiLineCV = textCV.findChild("MultiLine");
				if (categoryCV != null) {
					text.setMultiLine((Boolean) multiLineCV.getValue());
				}
				textList.add(text);
			}
		}
		return textList;
	}

	// TODO throw specific exceptions, not a general exception
	private FontOptionsJson createFontOptionsFromConfigurationValue(final ConfigurationValue fontOptionsCV)
			throws Exception {
		if (fontOptionsCV == null) {
			return null;
		}
		// dig out font option values
		final FontOptionsJson fontOptions = new FontOptionsJson();
		fontOptions.setId((int)fontOptionsCV.getId());
		fontOptions.setName(fontOptionsCV.getKeyName());

		ConfigurationValue value;
		// font name
		value = fontOptionsCV.findChild("Style");
		if (value != null) {
			fontOptions.setStyle(value.getValue().toString());
		}
		// font size
		value = fontOptionsCV.findChild("Size");
		if (value != null) {
			fontOptions.setSize(Integer.parseInt(value.getValue().toString()));
		}
		// font color
		value = fontOptionsCV.findChild("Color");
		if (value != null) {
			fontOptions.setColor(value.getValue().toString());
		}
		// font alignment
		value = fontOptionsCV.findChild("Alignment");
		if (value != null) {
			fontOptions.setAlignment(Alignment.valueOf(value.getValue().toString()));
		}
		return fontOptions;
	}

	private ConfigurationValue createConfigurationValueFromFontOptions(final FontOptions fontOptions) {
		// TODO: Should we throw exception if any of the values are missing?
		if (fontOptions == null) {
			return null;
		}
		final ConfigurationValue fontOptionsCV = new ConfigurationValue("FontOptionsJson");
		fontOptionsCV.setId(fontOptions.getId());
		// font name
		ConfigurationValue value = new ConfigurationValue("Style");
		value.setValue(fontOptions.getStyle());
		fontOptionsCV.addChildValue(value);
		// font size
		value = new ConfigurationValue("Size");
		value.setValue(fontOptions.getSize());
		fontOptionsCV.addChildValue(value);
		// font color
		value = new ConfigurationValue("Color");
		value.setValue(fontOptions.getColor());
		fontOptionsCV.addChildValue(value);
		// font alignment
		value = new ConfigurationValue("Alignment");
		value.setValue(fontOptions.getAlignment());
		fontOptionsCV.addChildValue(value);

		return fontOptionsCV;
	}

	private List<Function> getFunctions(ConfigurationValue screenValue) {

		// check to see if the 'functions' bucket has any children.
		// if so, they are a list of function definitions.
		ConfigurationValue functionRoot = screenValue.findChild(ConfigurationKey.FUNCTIONS);
		List<Function> functions = new ArrayList<Function>();

		if (functionRoot != null) {

			for (ConfigurationValue func : functionRoot.getChildValues()) {
				FunctionJson f = new FunctionJson();
				f.setId((int)func.getId());
				f.setName(func.getTag().toString());
				f.setActive((Boolean) func.getValue());
				StationsAuditCriteria auditCriteria = getStationsAuditCriteria(func);
				f.setAuditCriteria(auditCriteria);

				functions.add(f);
			}
		}

		return functions;
	}

	private StationsAuditCriteria getStationsAuditCriteria(ConfigurationValue func) {
		StationsAuditCriteria auditCriteria = new StationsAuditCriteriaJson();
		auditCriteria.setAllStations(true);

		if (func.getKeyName().equals("RedressNumber")) {
			List<AuditField> stations = new ArrayList<AuditField>();
			AuditFieldJson station = new AuditFieldJson("ATL", false);
			stations.add(station);
			station = new AuditFieldJson("SEA", false);
			stations.add(station);
			station = new AuditFieldJson("MCO", false);
			stations.add(station);
			station = new AuditFieldJson("JFK", false);
			stations.add(station);
			auditCriteria.setStations(stations);
		} else if (func.getKeyName().equals("KnownTravelers")) {
			List<AuditField> stationsList = new ArrayList<AuditField>();
			AuditFieldJson station1 = new AuditFieldJson("ABC", false);
			stationsList.add(station1);
			station1 = new AuditFieldJson("DEF", false);
			stationsList.add(station1);
			station1 = new AuditFieldJson("GHI", true);
			stationsList.add(station1);
			station1 = new AuditFieldJson("JKL", false);
			stationsList.add(station1);
			auditCriteria.setStations(stationsList);
		}
		return auditCriteria;
	}

	@Override
	public List<ConfigurationValue> convertToFunctionConfigValues(ScreenConfiguration config) {

		List<Function> functions = config.getFunctions();
		List<ConfigurationValue> updates = new ArrayList<ConfigurationValue>();

		// iterate through list and convert to configuration values
		for (Function f : functions) {
			logger.debug("f = " + f);
			// create a new configuration value with just enough to update it.
			ConfigurationValue cv = new ConfigurationValue();
			cv.setId(f.getId());
			cv.setTag(f.getName());
			cv.setKeyName(f.getName().replace(" ", ""));
			cv.setValue(f.isActive());
			updates.add(cv);
		}

		return updates;
	}

	@Override
	public List<ConfigurationValue> convertToTextConfigValues(final ScreenConfiguration screenConfig) {
		final List<Text> textList = screenConfig.getText();
		final List<ConfigurationValue> textListCV = new ArrayList<ConfigurationValue>();
		// iterate through list and convert to configuration values
		for (final Text text : textList) {
			// create a new configuration value with just enough to update it.
			final ConfigurationValue textCV = new ConfigurationValue(text.getName());
			if (text instanceof TextEntry) {
				textCV.setObjectType(TextEntryJson.class.getName());
				textCV.setValue(((TextEntryJson) text).getValue());
			} else if (text instanceof ErrorText) {
				textCV.setObjectType(ErrorTextJson.class.getName());
				textCV.setValue(((ErrorText) text).getMessage());
			} else {
				logger.error("Invalid type for text configurations");
				continue;
			}
			textCV.setId(text.getId());
			// fontOptions
			ConfigurationValue propertyCV = createConfigurationValueFromFontOptions(text.getFontOptions());
			textCV.getChildValues().add(propertyCV);
			// category
			propertyCV = new ConfigurationValue("Category");
			propertyCV.setValue(text.getCategory().name());
			textCV.getChildValues().add(propertyCV);
			// multiLine
			propertyCV = new ConfigurationValue("MultiLine");
			propertyCV.setValue(text.isMultiLine());
			textCV.getChildValues().add(propertyCV);

			textListCV.add(textCV);
		}
		return textListCV;
	}

	@Override
	public List<ConfigurationValue> convertToRuleConfigValues(final ScreenConfiguration screenConfig) {
		if (screenConfig == null) {
			return null;
		}
		final List<Rule> rules = screenConfig.getRules();
		if (rules == null) {
			return null;
		}
		List<ConfigurationValue> updates = new ArrayList<ConfigurationValue>();
		// final ConfigurationValue rulesCV = new
		// ConfigurationValue(ConfigurationKey.RULES);
		for (final Rule rule : rules) {
			// TODO have to confirm the values for ruleName, screenName
			final ConfigurationValue ruleCV = new ConfigurationValue();
			// ruleCV.setId(rule.getId());
			ruleCV.setTag(rule.getRuleName());
			ruleCV.setKeyName(rule.getRuleName().replace(" ", ""));
			// tableDefinition
			final List<TableDefinition> tableDefinitions = rule.getTableDefinition();
			if (tableDefinitions != null && !tableDefinitions.isEmpty()) {
				for (final TableDefinition tableDefinition : tableDefinitions) {
					final ConfigurationValue tableDefinitionCV = createTableValue(tableDefinition);
					ruleCV.getChildValues().add(tableDefinitionCV);
				}
			}
			// ruleControls
			/*
			 * if (rule.getRuleControls() != null) {
			 * ruleCV.getChildValues().add(
			 * createRuleControlsCV(rule.getRuleControls())); }
			 */
			// rulesCV.getChildValues().add(ruleCV);
			updates.add(ruleCV);
		}
		return updates;
	}

	private ConfigurationValue createRuleControlsCV(final RuleControls ruleControls) {
		if (ruleControls == null) {
			return null;
		}
		final ConfigurationValue ruleControlsCV = new ConfigurationValue("ruleControls",
				ConfigurationValueEnum.GENERIC_VALUE);
		// ruleType
		if (ruleControls.getRuleType() != null) {
			final ConfigurationValue ruleTypeCV = new ConfigurationValue("ruleType",
					ConfigurationValueEnum.GENERIC_VALUE);
			ruleTypeCV.setValue(ruleControls.getRuleType());
			ruleControlsCV.getChildValues().add(ruleTypeCV);
		}
		// hasAddButton
		if (ruleControls.getHasAddButton()) {
			final ConfigurationValue hasAddButtonCV = new ConfigurationValue("hasAddButton",
					ConfigurationValueEnum.GENERIC_VALUE);
			hasAddButtonCV.setValue(ruleControls.getHasAddButton());
			ruleControlsCV.getChildValues().add(hasAddButtonCV);
		}
		// hasDeleteButton
		if (ruleControls.getHasDeleteButton()) {
			final ConfigurationValue hasDeleteButtonCV = new ConfigurationValue("hasDeleteButton",
					ConfigurationValueEnum.GENERIC_VALUE);
			hasDeleteButtonCV.setValue(ruleControls.getHasDeleteButton());
			ruleControlsCV.getChildValues().add(hasDeleteButtonCV);
		}
		return ruleControlsCV;
	}

	private TableValue createTableValue(final TableDefinition tableDefinition) {
		if (tableDefinition == null) {
			return null;
		}
		final TableValue tableValue = new TableValue();
		// FIXME Need to set this in the TableDefinitionJson
		tableValue.setKeyName("MileagePlanTable");
		final List<RowSpecification> rowSpecs = tableDefinition.getRowSpecification();
		if (rowSpecs != null && !rowSpecs.isEmpty()) {
			// Rows
			int rowCounter = 0;
			for (final RowSpecification rowSpec : rowSpecs) {
				tableValue.addRow(rowSpec.getRowValue());
				System.out.println("Added row: " + rowSpec.getRowValue());
				if (rowCounter == 0) {
					tableValue.addColumn(rowSpec.getRowName());
					System.out.println("Added column: " + rowSpec.getRowName());
					// Columns
					List<ColumnSpecification> colSpecs = rowSpec.getColSpecification();
					if (colSpecs != null && !colSpecs.isEmpty()) {
						for (final ColumnSpecification colSpec : colSpecs) {
							tableValue.addColumn(colSpec.getColumnName());
							System.out.println("Added column: " + colSpec.getColumnName());
						}
					}
					setValues(rowCounter, tableValue, rowSpec);
				} else if (rowCounter > 0) {
					setValues(rowCounter, tableValue, rowSpec);
				}
				rowCounter++;
			}
		}
		return tableValue;
	}

	private void setValues(int rowCounter, TableValue tableValue, RowSpecification rowSpec) {
		List<ColumnSpecification> colSpecs = rowSpec.getColSpecification();
		if (colSpecs != null && !colSpecs.isEmpty()) {
			int colCounter = 1;
			for (final ColumnSpecification colSpec : colSpecs) {
				/*
				 * TODO how to fill String rowWidget; String rowStyle; String
				 * columnWidget; String columnStyle;
				 */
				try {
					// System.out.println("rowCounter = " +
					// rowCounter);
					// System.out.println("colCounter = " +
					// colCounter);
					tableValue.setValue(rowCounter, colCounter, colSpec.getColumnValue());
					System.out.println("Set value: '" + colSpec.getColumnValue() + "' at row[" + rowCounter + "], col["
							+ colCounter + "]");
				} catch (TableRowException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (TableColumnException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				colCounter++;
			}
		}
	}

	private List<Rule> getRules(final ConfigurationValue configValue) {
		final ConfigurationValue rulesCV = configValue.findChild(ConfigurationKey.RULES);
		if (rulesCV == null) {
			return null;
		}
		final List<Rule> rules = new ArrayList<Rule>();
		for (final ConfigurationValue ruleCV : rulesCV.getChildValues()) {
			final RuleJson rule = new RuleJson();
			// TODO confirm the id, rulename, description values
			if (ruleCV.getTag() != null) {
				rule.setRuleName(ruleCV.getTag().toString());
				rule.setScreenName(ruleCV.getTag().toString());
				rule.setDescription(ruleCV.getTag().toString());
			}
			final List<TableDefinition> tableDefinitions = getTableDefinitions(ruleCV);
			rule.setTableDefinition(tableDefinitions);
			// ruleControls
			final ConfigurationValue ruleControlsCV = rulesCV.findChild("ruleControls");
			if (ruleControlsCV != null) {
				final RuleControls ruleControls = getRuleControls(ruleControlsCV);
				rule.setRuleControls(ruleControls);
			} else {
				// TODO Remove once RuleControls in database
				RuleControls ruleControls = new RuleControlsJson();
				ruleControls.setHasAddButton(true);
				ruleControls.setHasDeleteButton(false);
				ruleControls.setRuleType("MileageTable");
				rule.setRuleControls(ruleControls);
			}
			rules.add(rule);
		}
		return rules;
	}

	private List<TableDefinition> getTableDefinitions(final ConfigurationValue tableDefinitionCV) {
		if (tableDefinitionCV == null) {
			return null;
		}
		final Set<ConfigurationValue> childCVs = tableDefinitionCV.getChildValues();
		if (childCVs == null || childCVs.isEmpty()) {
			return null;
		}
		final List<TableDefinition> tableDefinitions = new ArrayList<TableDefinition>();
		for (final ConfigurationValue childCV : childCVs) {
			if (childCV.getObjectType() != null && childCV.getObjectType().equals("TableValue")) {
				final TableDefinitionJson tableDefinition = getTableDefinition(childCV);
				tableDefinitions.add(tableDefinition);
			}
		}
		return tableDefinitions;
	}

	private TableDefinitionJson getTableDefinition(final ConfigurationValue tableDefinitionCV) {
		if (tableDefinitionCV == null) {
			return null;
		}
		final TableDefinitionJson tableDefinition = new TableDefinitionJson();
		// rowCount
		tableDefinition.setRowCount(tableDefinitionCV.getTableRows().size());
		// columnCount
		tableDefinition.setColumnCount(tableDefinitionCV.getTableColumns().size() - 1);

		final List<RowSpecification> rowSpecifications = new ArrayList<RowSpecification>();
		for (Iterator<TableRow> rowIter = tableDefinitionCV.getTableRows().iterator(); rowIter.hasNext();) {
			TableRow tableRow = rowIter.next();
			final RowSpecificationJson rowSpecification = new RowSpecificationJson();
			// rowValue
			rowSpecification.setRowValue(tableRow.getName());
			// FIXME Do not hard code
			rowSpecification.setRowWidget("TextBox");
			final List<ColumnSpecification> columnSpecifications = new ArrayList<ColumnSpecification>();
			for (Iterator<TableColumn> colIter = tableDefinitionCV.getTableColumns().iterator(); colIter.hasNext();) {
				TableColumn tableColumn = colIter.next();
				if (tableColumn.getOrdinal() == 0) {
					// rowName
					rowSpecification.setRowName(tableColumn.getName());
					continue;
				}
				ColumnSpecificationJson columnSpecification = new ColumnSpecificationJson();
				columnSpecification.setColumnName(tableColumn.getName());
				try {
					columnSpecification.setColumnValue(tableDefinitionCV
							.findChild(tableRow.getOrdinal() + ":" + tableColumn.getOrdinal()).getValue().toString());
					// FIXME: Do not hard code
					if (columnSpecification.getColumnValue().equals("true")
							|| columnSpecification.getColumnValue().equals("false")) {
						columnSpecification.setColumnWidget("ON-OFF");
					} else {
						columnSpecification.setColumnWidget("TextBox");
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					System.out.println("tableColumn.getOrdinal() = " + tableColumn.getOrdinal());
					System.out.println("tableRow.getOrdinal() = " + tableRow.getOrdinal());
				}
				columnSpecifications.add(columnSpecification);
			}
			rowSpecification.setColSpecification(columnSpecifications);
			rowSpecifications.add(rowSpecification);
		}
		tableDefinition.setRowSpecification(rowSpecifications);
		return tableDefinition;
	}

	private RuleControls getRuleControls(final ConfigurationValue ruleControlsCV) {
		if (ruleControlsCV == null) {
			return null;
		}
		final RuleControls ruleControls = new RuleControlsJson();
		// ruleType
		final ConfigurationValue ruleTypeCV = ruleControlsCV.findChild("ruleType");
		if (ruleTypeCV != null) {
			ruleControls.setRuleType((String) ruleTypeCV.getValue());
		}
		// hasAddButton
		final ConfigurationValue hasAddButtonCV = ruleControlsCV.findChild("hasAddButton");
		if (hasAddButtonCV != null) {
			ruleControls.setHasAddButton((Boolean) hasAddButtonCV.getValue());
		}
		// hasDeleteButton
		final ConfigurationValue hasDeleteButtonCV = ruleControlsCV.findChild("hasDeleteButton");
		if (hasDeleteButtonCV != null) {
			ruleControls.setHasDeleteButton((Boolean) hasDeleteButtonCV.getValue());
		}
		return ruleControls;
	}
}
